package com.fasteat.mall.controller;

import com.fasteat.common.entity.Result;
import com.fasteat.common.util.FileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/mall/file")
@CrossOrigin
@Api(description = "文件管理")
public class FileController {

	@PostMapping("/upload")
	@ApiOperation("文件上传")
	public Result upload(MultipartFile multipartFile) {
		if(multipartFile == null) {
			return Result.error("请选择图片！");
		}
		String ret = FileUtil.upload(multipartFile);
		return Result.success().data(ret);
	}

	@PostMapping("/delete")
	@ApiOperation("文件删除（暂时无法使用）")
	public Result delete(@RequestBody @ApiParam(required = true,value = "url") String url) {
		String ret = FileUtil.delete(url);
		return Result.success().data(ret);
	}
}
